package com.yc.controller.xcx;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.yc.controller.weixin.GenericController;
import com.yc.entity.Page;
import com.yc.entity.xcx.PickerObject;
import com.yc.service.system.dictionaries.DictionariesManager;
import com.yc.service.system.doctor.IDoctorAdditionService;
import com.yc.service.system.doctor.IDoctorBCBookingService;
import com.yc.util.PageData;
import com.yc.util.ReturnModel;

@Controller
@RequestMapping("/app/doctor")
public class EDoctorController extends GenericController {

	@Resource
	private DictionariesManager dictionariesService;

	@Resource
	private IDoctorAdditionService doctorAdditionService;

	@Resource
	private IDoctorBCBookingService doctorBCBookingService;

	// 职称下拉表
	@RequestMapping(value = "/getLevelList")
	public void getHospitalList(HttpServletResponse response) throws Exception {

		PageData pd = new PageData();
		pd = this.getPageData();

		List<PageData> list = dictionariesService.findByParentBianma(pd);

		ReturnModel returnModel = new ReturnModel();
		PickerObject obj = new PickerObject();

		List ids = new ArrayList<String>();
		List values = new ArrayList<String>();

		ids.add(0);
		values.add("请选择职称");

		for (PageData item : list) {
			ids.add(item.getString("DICTIONARIES_ID").toString());
			values.add(item.getString("NAME").toString());
		}

		obj.setIds(ids);
		obj.setValues(values);

		returnModel.setResult(true);
		returnModel.setReason(null);
		returnModel.setDatum(obj);

		this.renderString(response, returnModel);

	}

	@RequestMapping(value = "/getAdditionList")
	public void getAdditionList(HttpServletResponse response) throws Exception {

		PageData pd = new PageData();
		pd = this.getPageData();

		Page page = new Page();
		page.setPd(pd);

		ReturnModel returnModel = new ReturnModel();
		returnModel.setResult(true);
		returnModel.setReason(null);

		try {

			List<PageData> list = doctorAdditionService.getDoctorAdditionList(page);
			returnModel.setDatum(list);

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			returnModel.setResult(false);
			returnModel.setReason(e.getMessage());
			returnModel.setDatum(null);
		}

		renderString(response, returnModel);

	}
	
	@RequestMapping(value = "/getBCBookingList")
	public void getBCBookingList(HttpServletResponse response) throws Exception {

		PageData pd = new PageData();
		pd = this.getPageData();

		Page page = new Page();
		page.setPd(pd);

		ReturnModel returnModel = new ReturnModel();
		returnModel.setResult(true);
		returnModel.setReason(null);

		try {

			List<PageData> list = doctorBCBookingService.getBCBookingist(page);
			returnModel.setDatum(list);

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			returnModel.setResult(false);
			returnModel.setReason(e.getMessage());
			returnModel.setDatum(null);
		}

		renderString(response, returnModel);

	}
	
	
	@RequestMapping(value = "/getBCBookingItem")
	public void getBCBookingItem(HttpServletResponse response) throws Exception {

		PageData pd = new PageData();
		pd = this.getPageData();


		ReturnModel returnModel = new ReturnModel();
		returnModel.setResult(true);
		returnModel.setReason(null);

		try {

			PageData item = doctorBCBookingService.findById(pd);
			returnModel.setDatum(item);

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			returnModel.setResult(false);
			returnModel.setReason(e.getMessage());
			returnModel.setDatum(null);
		}

		renderString(response, returnModel);

	}
	
	
	@RequestMapping(value = "/getAdditionItem")
	public void getAdditionItem(HttpServletResponse response) throws Exception {

		PageData pd = new PageData();
		pd = this.getPageData();


		ReturnModel returnModel = new ReturnModel();
		returnModel.setResult(true);
		returnModel.setReason(null);

		try {

			PageData item = doctorAdditionService.findById(pd);
			returnModel.setDatum(item);

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			returnModel.setResult(false);
			returnModel.setReason(e.getMessage());
			returnModel.setDatum(null);
		}

		renderString(response, returnModel);

	}
	
	@RequestMapping(value = "/getFreeBookingList")
	public void getFreeBookingList(HttpServletResponse response) throws Exception {

		PageData pd = new PageData();
		pd = this.getPageData();

		Page page = new Page();
		page.setPd(pd);

		ReturnModel returnModel = new ReturnModel();
		returnModel.setResult(true);
		returnModel.setReason(null);

		try {

			List<PageData> list = doctorBCBookingService.getBCBookingist(page);
			returnModel.setDatum(list);

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			returnModel.setResult(false);
			returnModel.setReason(e.getMessage());
			returnModel.setDatum(null);
		}

		renderString(response, returnModel);

	}
	


}
